<?php
namespace Mobile\Controller;
use Think\Controller;


class SignupController extends Controller {
            // protected $AppId     = "wxabb279a07f54bf32";//Appid 公众号的唯一标识(开发者申请之后系统分配的)
            // protected $AppSecret = "3ea7164934c98ecd413f5549dd7780bc";//AppSecret  公共号的密钥
            // protected $uid       = 347;    
    
    // 构造方法
    // public function __construct() {
    //     //测试
    //     if($_GET['test'] ){
    //                         $_SESSION['fbh_openid'] = "ojocnvw15xWKDxuChL6djnjRV36E";
    //                     }

    //     $callbackurl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];   // URL
        
    //     if(!$_SESSION['fbh_openid']){
    //         $_SESSION['fbh_openid'] = Oauth2::getMyopenid($callbackurl,$this->AppId,$this->AppSecret);
    //     }
    //                 $openid = $_SESSION['fbh_openid'];

    //      if ($openid) {
    //                     $data = M()->table('hfd_signup1')->where('openid="'.$openid.'"')->find();
    //                     if(!$data){
    //                         $hfd_info = Oauth2::scan_get_userinfo($openid,$this->uid); 
    //                         if ($hfd_info ['subscribe'] === 0){
    //                             header ( 'Location:http://mp.weixin.qq.com/s/yAJduJevDxhNepM-PHw7cA' );
    //                         }else if($hfd_info['openid']){
    //                             $this->addInfo($hfd_info);
    //                         }
                            
    //                             $this->addInfo($hfd_info);
    //                     }
    //                 }
    //         }
 
    //     public function addInfo($info){
    //      $data['openid']     = $info['openid']; 
    //      $data['headimgurl'] = preg_replace("/\/0/is", "/96", $info['headimgurl']);
    //      $data['nickname']   = $info['nickname'];
    //      $data['addtime']    = time();
    //      $sql = " INSERT INTO  `hfd_signup1` (`openid`,`nickname`,`headimgurl`,`addtime`) VALUES ('".$data['openid']."',hex('".$data['nickname']."'),'".$data['headimgurl']."','".$data['addtime']."') ";
    //      $var_add = M()->query($sql); 
    //  }
    //首页显示
    public function index(){
        // $where['dg_openid']  = $_SESSION['fbh_openid'];
        $houseid=$_GET['h'];
        $row=M()->table("rent")->where('id='.$houseid)->find();
        $this->assign("title",$row['title']);
        $this->assign("address",$row['dizhi']);
        $this->assign("floor",$row['floor']);
        //$this->assign("maxfloor",$row['maxfloor']);
        $this->assign("imgurl",$row['imgurl']);
        $this->assign("houseid",$houseid);
        $rooms=M()->table("fenrent")->where("rel_id=".$houseid)->select();
        $this->assign("rooms",$rooms);
        $this->assign("price",$rooms);
        //$userinfo =M()->table("hfd_signup1")->field("name,tel,date,time")->where("openid='".$_SESSION["fbh_openid"]."'")->find();
        // if($userinfo['name']=='' || $userinfo['tel']==''){
        //  $this->assign("status",0);
        //  }
        //  else{
        //  $this->assign("status",1);
        //  }
        $this->display();
    }
   
    public function save(){ 
        //$data['openid'] = $_SESSION['fbh_openid'];
        $data['title'] = $_POST['title'];
        $data['name'] = $_POST['name'];
        $data['tel']  = $_POST['tel'];
        $data['date']  = $_POST['date'];
        $data['sex'] = $_POST['sex'];
        $data['time']  = $_POST['time'];
        $data['houseid'] = $_POST['houseid'];
        $data['room'] = $_POST['room'];
        $data['addtime'] = time();
        $data['textarea'] = $_POST['textarea'];
        $res = M('hfd_yuyue')->data($data)->add();
        if($res){
            $this->ajaxReturn("1","JSON");
        }else{
            $this->ajaxReturn("0","JSON");
        }
    }




}
?>